home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
081-090
/
amok87
/
rekursionen
/
hilbert.mod
< prev
next >
Wrap
Text File
|
1993-11-04
|
3KB
|
110 lines
(*------------------------------------------------------------------------------
:Program. hilbert.mod
:Contents. zeichnet (rekursiv) die Hilbert-Kurven
:Author. Matthias Scherrer
:Address. Baselstrasse 63, CH-4242 Laufen
:Phone. ++(0)61/7613975
:Copyright. PD
:Language. Oberon
:Translator. Oberon V3.00d
:History. V1.0,24-Nov-92 fuer Oberon V2.14d
:History. V1.1,29-Dec-92 angepasst an Oberon V3.00d, Optimierungen
am Source
------------------------------------------------------------------------------*)
MODULE hilbert;
IMPORT di: Display, io, Mouse;
CONST
width = 716;
height = 472;
TYPE
Pos = RECORD
x,y : INTEGER;
END;
VAR
screen : di.ScreenPtr;
b : BOOLEAN;
cord : Pos;
n,s : INTEGER;
(*------------------------------------------------------------*)
(* Proceduren fuer Intuition (Screen oeffnen/schliessen) *)
(*------------------------------------------------------------*)
PROCEDURE InitGraph;
BEGIN
NEW(screen);
b:=di.OpenScreen(screen,"Hilbert-Kurven",0,0,width,height,1,TRUE,TRUE);
END InitGraph;
PROCEDURE Close;
BEGIN
di.Close(screen)
(* $IFNOT GarbageCollector *)
DISPOSE(screen);
(* $END *)
END Close;
(*------------------------------------------------------------*)
(* Proceduren, die die Zwischenstuecke zeichnen *)
(*------------------------------------------------------------*)
PROCEDURE P(lx,ly : INTEGER);
BEGIN
cord.x:=cord.x+lx; cord.y:=cord.y+ly;
di.Draw(screen,cord.x,cord.y)
END P;
(*------------------------------------------------------------*)
(* Hier die Rekursion *)
(*------------------------------------------------------------*)
PROCEDURE Draw(n,l,z : INTEGER);
BEGIN
IF n>0 THEN
CASE z OF
0: Draw(n-1,l,1); P(-l, 0); Draw(n-1,l,0); P( 0, l);
Draw(n-1,l,0); P( l, 0); Draw(n-1,l,3);
| 1: Draw(n-1,l,0); P( 0, l); Draw(n-1,l,1); P(-l, 0);
Draw(n-1,l,1); P( 0,-l); Draw(n-1,l,2);
| 2: Draw(n-1,l,3); P( l, 0); Draw(n-1,l,2); P( 0,-l);
Draw(n-1,l,2); P(-l, 0); Draw(n-1,l,1);
| 3: Draw(n-1,l,2); P( 0,-l); Draw(n-1,l,3); P( l, 0);
Draw(n-1,l,3); P( 0, l); Draw(n-1,l,0);
END; (* CASE *)
END; (* IF *)
END Draw;
(*------------------------------------------------------------*)
(* Und noch das Hauptprogramm... *)
(*------------------------------------------------------------*)
BEGIN
io.WriteString("Seitenlaenge : "); b:=io.ReadInteger(s);
io.WriteString("Tiefe (n) : "); b:=io.ReadInteger(n);
InitGraph;
cord.x:=width-1; cord.y:=15; (* Anfangskoordinaten *)
di.Move(screen,cord.x,cord.y);
Draw(n,s,0); (* n, Seitenlaenge, 0=Oeffnung nach rechts *)
Mouse.WaitLMB;
Close;
END hilbert.